package org.chuan.hisports.service.Imp;

import org.chuan.hisports.dao.CoaSchemeDao;
import org.chuan.hisports.dao.UserDao;
import org.chuan.hisports.entity.CoaScheme;
import org.chuan.hisports.entity.User;
import org.chuan.hisports.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.Format;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Service
public class UserServiceImp implements UserService {
    @Autowired
    UserDao userDao;
    @Autowired
    CoaSchemeDao coaSchemeDao;
    @Override
    public String test() {
        List<User> users = userDao.test();
        System.out.println(users.toString());
        return "1";
    }
    @Override
    public String register(User user){
        userDao.register(user);
        System.out.println(user.getId());
        return  user.getId()+"";
    }

    @Override
    public User selectById(String id){
        User user = userDao.selectById(id);
        return user;
    }

    @Override
    public User login(String phone,String password){
        User user = userDao.login(phone,password);
        return user;
    }

    @Override
    public boolean checkPhoneExist(String phone) {
        String flag = userDao.checkPhoneExist(phone);

        if (flag == null)
            //未注册返回false
            return false;
        else
            //注册返回真
            return true;
    }
//  修改用户名，密码，头像等
    //修改用户密码
    @Override
    public boolean modifyPassword(String phone, String password) {
        String realpw = userDao.checkPassword(phone);
        if (realpw == password){
            return false;
        }else{
            userDao.modifyPassword(phone,password);
            return true;
        }

    }

    //修改用户头像
    @Override
    public void modifyAvatar(String id,String vacatar){
        userDao.modifyAvatar(id, vacatar);
    }

    //修改用户名
    @Override
    public User modifyNickname(String id, String nickname) {
        userDao.modifyNickname(id, nickname);
        User user = selectById(id);
        return user;
    }



    //使用“会员”+当前时间生成默认用户名，然后返回
    @Override
    public String GenerateUserName(String time) {

        String userName = "会员"+ time.substring(3,time.length());
        return userName;
    }

    //查看健身会员的健身教练以及方案
    @Override
    public CoaScheme readSchemeByUid(String uid){
        CoaScheme coaScheme = coaSchemeDao.selectByUid(uid);
        return  coaScheme;
    }
}
